/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dtn.wsn.dao;

import com.dtn.wsn.database.ConnectionPool;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *Data Access object for CollectionHistory entity
 * @author hao
 */

public class CollectionHistoryDAO {
    private ConnectionPool connectionPool;

    public CollectionHistoryDAO(ConnectionPool connectionPool) {
        this.connectionPool = connectionPool;
    }
    /**
     * update the status by timestamp
     * @param timestamp
     * @param status
     * @return 
     */
    public int updateStatusByTimestample(String timestamp, String status){
    
        int updateQuery = 0;
        String sql = "update collecthistory set status = '"+ status +"' where timestamp = '"+ timestamp +"'";
        //System.out.println(sql);
        try {
            Connection cn = connectionPool.getConnection();
            
            Statement stmt = cn.createStatement();
            updateQuery = stmt.executeUpdate(sql);

            connectionPool.freeConnection(cn);
        } catch (SQLException ex) {
            Logger.getLogger(DataDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return updateQuery;
    }
    
}
